const express = require('express')
const app = express()

var z1 = (req, res, next) => {
    req.token = '我是中间件留下的'
    next()
}

app.use(z1)


const cors = require('cors')
app.use(cors())



const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.get('/jsonp', (req, res) => {
    console.log(req.token, 888888)
    //?  query
    //console.log(req.query.callback, 999) //  abc
    // res.send('123')
    res.send(req.query.callback + "(123)")   //  abc(123)
    // setTimeout(() => {
    //     res.send(req.query.callback + "(123)")   //  abc(123)
    // }, 5000)
})


app.post('/login', (req, res) => {
    console.log(req.body, 888)

    var arr60=['admin','jack']
    var arr61=['admin1','jack1']


    const { user, pwd } = req.body
    if (user == 'admin' && pwd == '123456') {
        res.json({
            msg: '登录成功',
            status: 1,
            info: req.body
        })

    } else {
        res.json({
            msg: '登录失败，请重新登录',
            status: 0
        })
    }

})

// app.post('/register', (req, res) => {
//     console.log(req.body, 888)
//     res.json(req.body)
// })







app.listen(2000, () => {
    console.log('服务器:http://127.0.0.1:2000')
})